package pl.polidea.imf.blackberry.util;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import pl.polidea.imf.common.java.impl.http.ConnectionTimeOutWatchDog;

public class HttpHelper {
	
	public static boolean ping(String url) {
		boolean result = false;
		try {
			HttpConnection connection = (HttpConnection) Connector.open(url);
			ConnectionTimeOutWatchDog watchDog = new ConnectionTimeOutWatchDog(connection);
			watchDog.watch();
			int responseCode = connection.getResponseCode();
			watchDog.cancel();
			System.out.println("Testing connection: " + url + "response with code: " + responseCode);
			connection.close();
			result = true;
		}  catch (Throwable t) {
			result = false;
			System.out.println("Cannot use connection: " + url + "error: " + t.toString());
		}
		return result;
	} 
}
